"""
-*- coding: utf-8 -*-
@Time : 2022/5/18 19:04
@Author : XGT-Python
"""
from proxy_db import DB_Mongo
from proxy_fetcher import kuai_da_li, yun_dai_li, all_word
from config import logging
from proxy_validata import validata_ip


def start():
    # 连接数据库
    db = DB_Mongo()
    # 下载IP
    for ip in kuai_da_li():
        logging.info(ip)
        # 验证IP
        if validata_ip(ip):
            # 通过验证后，保存ip
            db.insert(ip)
    # 关闭连接
    db.close()
    for ip in yun_dai_li():
        logging.info(ip)
        # 验证IP
        if validata_ip(ip):
            # 通过验证后，保存ip
            db.insert(ip)
        # 关闭连接
    db.close()


if __name__ == '__main__':
    start()
